package cn.xgc;

import cn.xgc.entity.News;

import java.util.ArrayList;
import java.util.List;

//List研究
public class Test2 {
    public static void main(String[] args) {

        List<News> newsList = new ArrayList<News>();
        //add添加列表元素
        newsList.add(new News("新闻1","随便编的内容1"));
        newsList.add(new News("新闻2","随便编的内容2"));
        newsList.add(new News("新闻3","随便编的内容3"));

        //remove 删除指定元素
        newsList.remove(1);

        //set 完成列表元素的修改
        newsList.set(1,new News("新闻4","随便编的内容4"));
        //get 根据下标获取元素
        System.out.println(newsList.get(0));
        //size 返回列表的长度
        System.out.println(newsList.size());

        //contains 判断对象是否存在于列表中
        News news = new News("新闻5","随便编的内容5");
        newsList.add(news);
        System.out.println(newsList.contains(news));


        for (News newsx:newsList) {
            System.out.println(newsx);
        }

    }
}
